package com.cal.utms.model.maintenance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cal.utms.dao.maintenance.FundManagerDaoImpl;
import com.cal.utms.dto.maintenance.FMContactPersonDto;
import com.cal.utms.dto.maintenance.FundManagerDto;
import com.cal.utms.entity.FundManager;
import com.cal.utms.entity.FundManagerContactPerson;

public class FundManagerModel {

	protected FundManagerDaoImpl fundManagerDao;

	/**
	 * 
	 * @return FundManagerDao
	 */
	public FundManagerDaoImpl getFundManagerDao() {
		
		if (fundManagerDao == null) {
			fundManagerDao = new FundManagerDaoImpl();
		}
		
		return fundManagerDao;
	}

	public void setFundManagerDao(FundManagerDaoImpl fundManagerDao) {
		this.fundManagerDao = fundManagerDao;
	}

	public List<Map<String, String>> getFundManagerList() {
		
		List<FundManager> fundManagerList = this.getFundManagerDao().getFundManagerList();
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		if (fundManagerList != null) {
			for (FundManager fundManager : fundManagerList) {
				Map<String, String> fundManagers = new HashMap<String, String>();
				// fundManagers.
				fundManagers.put("id", String.valueOf(fundManager.getId()));
				fundManagers.put("name", fundManager.getFmName());
				list.add(fundManagers);
			}
		}
		return list;
	}

	public static FundManager createFundManagerModel(FundManagerDto fundManagerBean) {
		FundManager fundManager = new FundManager();
		fundManager.setFmAddress(fundManagerBean.getFmAddress());
		fundManager.setFmBusinessRegNo(fundManagerBean.getFmBusinessRegNo());
		fundManager.setFmCode(fundManagerBean.getFmCode());
		fundManager.setFmEmail(fundManagerBean.getFmEmail());
		fundManager.setFmFax(fundManagerBean.getFmFax());
		fundManager.setFmName(fundManagerBean.getFmName());
		fundManager.setFmPhone(fundManagerBean.getFmPhone());
		return fundManager;
	}

	public static List<FundManagerDto> createFundManagerBealList(List<FundManager> fundManagers) {
		List<FundManagerDto> managers = new ArrayList<FundManagerDto>();
		for (FundManager fundManager : fundManagers) {
			FundManagerDto bean = new FundManagerDto();
			bean.setFmAddress(fundManager.getFmAddress());
			bean.setFmBusinessRegNo(fundManager.getFmBusinessRegNo());
			bean.setFmCode(fundManager.getFmCode());
			bean.setFmEmail(fundManager.getFmEmail());
			bean.setFmFax(fundManager.getFmFax());
			bean.setFmName(fundManager.getFmName());
			bean.setFmPhone(fundManager.getFmPhone());
			bean.setId(fundManager.getId());
			managers.add(bean);
		}
		return managers;
	}

	public static List<FMContactPersonDto> createFmContactPersonBeanList(List<FundManagerContactPerson> contactPersons) {
		List<FMContactPersonDto> personBeans = new ArrayList<FMContactPersonDto>();
		for (FundManagerContactPerson fundManagerContactPerson : contactPersons) {
			FMContactPersonDto bean = new FMContactPersonDto();
			bean.setCpDesignation(fundManagerContactPerson.getCpDesignation());
			bean.setCpEmail(fundManagerContactPerson.getCpEmail());
			bean.setCpFax(fundManagerContactPerson.getCpFax());
			bean.setCpName(fundManagerContactPerson.getCpName());
			bean.setCpPhone(fundManagerContactPerson.getCpPhone());
			bean.setId(fundManagerContactPerson.getId());
			personBeans.add(bean);
		}
		return personBeans;
	}
							
	public static FundManager createFundManagerModelWithId(FundManagerDto fundManagerBean) {

		FundManager fundManager = new FundManager();
		fundManager.setFmAddress(fundManagerBean.getFmAddress());
		fundManager.setFmBusinessRegNo(fundManagerBean.getFmBusinessRegNo());
		fundManager.setFmCode(fundManagerBean.getFmCode());
		fundManager.setFmEmail(fundManagerBean.getFmEmail());
		fundManager.setFmFax(fundManagerBean.getFmFax());
		fundManager.setFmName(fundManagerBean.getFmName());
		fundManager.setFmPhone(fundManagerBean.getFmPhone());
		fundManager.setId(fundManagerBean.getId());
		return fundManager;
	}
}
